* by the HTML serialization specification, and replace this node
* in its parent by that string.
*
+ * @param array $config Balancer configuration; see Balancer::__construct().
+ *
* @see __toString()
*/
- public function flatten( $tidyCompat = false ) {
+ public function flatten( array $config ) {
Assert::parameter( $this->parent !== null, '$this', 'must be a child' );
Assert::parameter( $this->parent !== 'flat', '$this', 'already flat' );
$idx = array_search( $this, $this->parent->children, true );
Assert::parameter(
$idx !== false, '$this', 'must be a child of its parent'
);
+ $tidyCompat = $config['tidyCompat'];
if ( $tidyCompat ) {
$blank = true;
foreach ( $this->children as $elt ) {
if ( !is_string( $elt ) ) {
- $elt = $elt->flatten( $tidyCompat );
+ $elt = $elt->flatten( $config );
}
if ( $blank && preg_match( '/[^\t\n\f\r ]/', $elt ) ) {
$blank = false;
*/
public $fosterParentMode = false;
/**
- * Tidy compatibility mode, determines behavior of body/blockquote
+ * Configuration options governing flattening.
+ * @var array $config
+ * @see Balancer::__construct()
*/
- public $tidyCompat = false;
+ private $config;
/**
* Reference to the current element
*/
/**
* Create a new BalanceStack with a single BalanceElement on it,
* representing the root <html> node.
+ * @param array $config Balancer configuration; see Balancer::_construct().
*/
- public function __construct() {
+ public function __construct( array $config ) {
// always a root <html> element on the stack
array_push(
$this->elements,
new BalanceElement( BalanceSets::HTML_NAMESPACE, 'html', [] )
);
$this->currentNode = $this->elements[0];
+ $this->config = $config;
}
/**
$out = '';
foreach ( $this->elements[0]->children as $elt ) {
$out .= is_string( $elt ) ? $elt :
- $elt->flatten( $this->tidyCompat );
+ $elt->flatten( $this->config );
}
return $out;
}
) {
$this->fosterParent( $value );
} elseif (
- $this->tidyCompat && !$isComment &&
+ $this->config['tidyCompat'] && !$isComment &&
$this->currentNode->isA( BalanceSets::$tidyPWrapSet )
) {
$this->insertHTMLELement( 'mw:p-wrap', [] );
$this->currentNode = null;
}
if ( !$elt->isHtmlNamed( 'mw:p-wrap' ) ) {
- $elt->flatten( $this->tidyCompat );
+ $elt->flatten( $this->config );
}
}
// otherwise, it will eventually serialize when the parent
// is serialized, we just hold onto the memory for its
// tree of objects a little longer.
- $elt->flatten( $this->tidyCompat );
+ $elt->flatten( $this->config );
}
Assert::postcondition(
array_search( $elt, $this->elements, true ) === false,
$parent = $this->elements[0]; // the `html` element.
}
- if ( $this->tidyCompat ) {
+ if ( $this->config['tidyCompat'] ) {
if ( is_string( $elt ) ) {
// We're fostering text: do we need a p-wrapper?
if ( $parent->isA( BalanceSets::$tidyPWrapSet ) ) {
private $afe;
private $stack;
private $strict;
- private $tidyCompat;
private $allowComments;
+ private $config;
private $textIntegrationMode;
private $pendingTableText;
* false to get a bit more performance.
*/
public function __construct( array $config = [] ) {
- $config = $config + [
+ $this->config = $config = $config + [
'strict' => false,
'allowedHtmlElements' => null,
'tidyCompat' => false,
];
$this->allowedHtmlElements = $config['allowedHtmlElements'];
$this->strict = $config['strict'];
- $this->tidyCompat = $config['tidyCompat'];
$this->allowComments = $config['allowComments'];
if ( $this->allowedHtmlElements !== null ) {
// Sanity check!
$this->parseMode = 'inBodyMode';
$this->bitsIterator = new ExplodeIterator( '<', $text );
$this->afe = new BalanceActiveFormattingElements();
- $this->stack = new BalanceStack();
- $this->stack->tidyCompat = $this->tidyCompat;
+ $this->stack = new BalanceStack( $this->config );
$this->processingCallback = $processingCallback;
$this->processingArgs = $processingArgs;